#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
queue<pair<ll,ll> > q1,q2,q3;
vector<bl> vec[2525],ck[2525];
vector<ll> g[2525];
ll n,m,k,sx,sy,ex,ey,dir[8][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
char s[6000060];
il void bfs(){
	ck[sx][sy]=1;
	q1.push(MP(sx,sy));
	ll now=0;
	while(!q1.empty()){
		while(!q1.empty()){
			pair<ll,ll> u=q1.front();
			q1.pop();
			if(u.fir==ex&&u.sec==ey){
				write(now);
				return;
			}
			fr(i,0,3){
				ll x=u.fir+dir[i][0],y=u.sec+dir[i][1];
				if(1<=x&&x<=n&&1<=y&&y<=m&&!ck[x][y]){
					ck[x][y]=1;
					if(!vec[x][y]) q1.push(MP(x,y));
					else{
						g[x][y]=1;
						q2.push(MP(x,y));
					}
				}
			}
		}
		while(!q2.empty()){
			pair<ll,ll> u=q2.front();
			q2.pop();
			q1.push(u);
			if(g[u.fir][u.sec]==k) continue;
			fr(i,0,7){
				ll x=u.fir+dir[i][0],y=u.sec+dir[i][1];
				if(1<=x&&x<=n&&1<=y&&y<=m&&!ck[x][y]){
					g[x][y]=g[u.fir][u.sec]+1;
					ck[x][y]=1;
					q2.push(MP(x,y));
				}
			}
		}
		now++;
	}
}
int main(){
	freopen("stamp.in","r",stdin);
	freopen("stamp.out","w",stdout);
	n=read();
	m=read();
	k=read();
	sx=read();
	sy=read();
	ex=read();
	ey=read();
	fr(i,1,n){
		scanf("%s",s+1);
		vec[i].resize(m+1);
		ck[i].resize(m+1);
		g[i].resize(m+1);
		fr(j,1,m) vec[i][j]=(s[j]=='#');
	}
	fr(i,1,n) fr(j,1,m) g[i][j]=k+1;
	bfs();
}
